package com.yixia.system.mapper.system;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yixia.system.domain.system.SysPost;
import org.apache.ibatis.annotations.Mapper;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author 35038
* @description 针对表【sys_post(岗位信息表)】的数据库操作Mapper
* @createDate 2023-08-05 23:09:35
* @Entity com.yixia.entity.SysPost
*/
@Mapper
public interface SysPostMapper extends BaseMapper<SysPost> {

    /**
     * 校验岗位名称
     *
     * @param postName 岗位名称
     * @return 结果
     */
    default SysPost checkPostNameUnique(String postName){
        LambdaQueryWrapper<SysPost> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysPost::getPostName, postName).eq(SysPost::getDelFlag, "0");
        return this.selectOne(queryWrapper);
    }

    /**
     * 校验岗位编码
     *
     * @param postCode 岗位编码
     * @return 结果
     */
    public default SysPost checkPostCodeUnique(String postCode){
        LambdaQueryWrapper<SysPost> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysPost::getPostCode, postCode).eq(SysPost::getDelFlag, "0");
        return this.selectOne(queryWrapper);
    }

    /**
     * 根据岗位ID批量删除岗位信息
     * @param postIds 岗位IDS
     * @return 结果
     */
    default int deletePostByPostIds(Long[] postIds){
        int update = 0;
        if(postIds.length > 0){
            List<Long> collect = Arrays.stream(postIds).collect(Collectors.toList());
            LambdaUpdateWrapper<SysPost> updateWrapper = new LambdaUpdateWrapper<>();
            updateWrapper.in(SysPost::getPostId, collect).set(SysPost::getDelFlag, "2");
            update = this.update(null, updateWrapper);
        }
        return update;
    }
}




